import os
import random

import uvicorn
from dotenv import load_dotenv

load_dotenv()
if __name__ == "__main__":
    #设置端口和host
    host = os.getenv("HOST")
    if not host:
        host = "127.0.0.1"
    port = os.getenv("PORT")
    if not port:
        port = random.randint(8000, 9000)
    # 设置debug
    debug = os.getenv("DEBUG")
    if debug == "True":
        debug = True
    else:
        debug = False
    # print(f"host: {host}, port: {port}, debug: {debug}")
    uvicorn.run("fastadmin.run:app", host=host, port=int(port), reload=bool(debug))